{% extends "admin/base.html" %}

{% block title %}Edit Server: {{ server.name }}{% endblock %}

{% block header_title %}Edit Server{% endblock %}

{% block content %}
<div class="max-w-2xl mx-auto">
    <a href="{{ url_for('admin_servers') }}" class="text-[var(--color-primary-500)] hover:text-[var(--color-primary-700)] mb-8 block">&larr; Back to Server Management</a>

    <div class="card-style">
        <h2 class="card-header text-2xl font-bold mb-6 pb-2">Editing: <span class="text-[var(--color-primary-500)]">{{ server.name }}</span></h2>
        
        <form action="{{ url_for('admin_edit_server_post', server_id=server.id) }}" method="post" class="space-y-6">
            <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
            
            <div>
                <label for="name" class="block text-sm font-medium">Server Name</label>
                <input type="text" name="name" id="name" required value="{{ server.name }}" class="mt-1 block w-full px-3 py-2 rounded-md shadow-sm">
            </div>
            
            <div>
                <label for="url" class="block text-sm font-medium">Server URL</label>
                <input type="url" name="url" id="url" required value="{{ server.url }}" class="mt-1 block w-full px-3 py-2 rounded-md shadow-sm">
            </div>

            <div>
                <label for="server_type" class="block text-sm font-medium">Server Type</label>
                <select name="server_type" id="server_type" class="mt-1 block w-full px-3 py-2 rounded-md shadow-sm">
                    <option value="ollama" {% if server.server_type == 'ollama' %}selected{% endif %}>Ollama</option>
                    <option value="vllm" {% if server.server_type == 'vllm' %}selected{% endif %}>vLLM (OpenAI-Compatible)</option>
                </select>
            </div>
            
            <div>
                <label for="api_key" class="block text-sm font-medium">API Key</label>
                <input type="password" name="api_key" id="api_key" autocomplete="new-password" class="mt-1 block w-full px-3 py-2 rounded-md shadow-sm" placeholder="Leave blank to keep current key">
                <div class="mt-2">
                    <label class="flex items-center">
                        <input type="checkbox" name="remove_api_key" value="true" class="h-4 w-4 rounded text-[var(--color-primary-600)] focus:ring-[var(--color-primary-500)]">
                        <span class="ml-2 text-sm text-gray-400">Remove existing API Key</span>
                    </label>
                </div>
            </div>
            
            <div class="flex justify-end pt-4">
                <button type="submit" class="w-full md:w-auto justify-center py-2 px-6 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-[var(--color-primary-600)] hover:bg-[var(--color-primary-700)]">
                    Save Changes
                </button>
            </div>
        </form>
    </div>
</div>
{% endblock %}
